package GUI;

import 试题和试卷.question;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public class revise {
    public JButton skipButton;
    public int index;
    JLabel questionInfo, question, answer,scoreLabel,standard;
    JScrollPane qScroller,aScroller,saScroller;
    public JTextArea answerContent,score,standardAnswer;
    public question currentquestion;
    int n,currRank;

    public static void main(String[] args) {
        new revise();
    }
    public revise(){
        skipButton=new JButton();
        skipButton.addActionListener(new skipListener());
    }

   public revise(int n, 试题和试卷.question currentquestion){
        this.currentquestion=currentquestion;
        this.n=n;
        this.index=n-1;
        String qContent=currentquestion.getText();

        questionInfo = new JLabel("第" + n + "题  简答题");
        question = new JLabel("题目：");
       standard= new JLabel("参考答案");
        answer = new JLabel("解答：");
        scoreLabel= new JLabel("得分：");




        Font bigFont = new Font("sanserif", Font.BOLD, 24);

        score= new JTextArea(1,20);

        JTextArea questionContent = new JTextArea(4, 20);
        questionContent.setText(qContent);
        questionContent.setLineWrap(true);
        questionContent.setWrapStyleWord(true);
        questionContent.setFont(bigFont);
        questionContent.setEditable(false);

        answerContent = new JTextArea(4, 20);
        answerContent.setLineWrap(true);
        answerContent.setWrapStyleWord(true);
        answerContent.setFont(bigFont);
        answerContent.setEditable(false);

       standardAnswer = new JTextArea(4, 20);
       standardAnswer.setLineWrap(true);
       standardAnswer.setWrapStyleWord(true);
       standardAnswer.setFont(bigFont);
       standardAnswer.setEditable(false);


        qScroller = new JScrollPane(questionContent);
        qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        aScroller = new JScrollPane(answerContent);
        aScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        aScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

       saScroller = new JScrollPane(standardAnswer);
       saScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
       saScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);


        questionInfo.setBounds(70, 10, 300, 20);
        qScroller.setBounds(70, 50, 500, 150);
        question.setBounds(20, 50, 50, 30);
        saScroller.setBounds(70,220,500, 150);
        standard.setBounds(20,220,50, 30);
        aScroller.setBounds(70,390,500, 150);
        answer.setBounds(20,380,50, 30);
        scoreLabel.setBounds(20,560,50,30);
        score.setBounds(70,560,500,30);


    }

    public void display(){
        reviseWindow.mainPanel.add(this.aScroller);
        reviseWindow.mainPanel.add(this.questionInfo);
        reviseWindow.mainPanel.add(this.question);
        reviseWindow.mainPanel.add(this.answer);
        reviseWindow.mainPanel.add(this.qScroller);
        reviseWindow.mainPanel.add(this.scoreLabel);
        reviseWindow.mainPanel.add(this.score);
        reviseWindow.mainPanel.add(this.saScroller);
        reviseWindow.mainPanel.add(this.standard);


    }

    public void remove(){
        reviseWindow.mainPanel.remove(this.aScroller);
        reviseWindow.mainPanel.remove(this.questionInfo);
        reviseWindow.mainPanel.remove(this.question);
        reviseWindow.mainPanel.remove(this.answer);
        reviseWindow.mainPanel.remove(this.qScroller);
        reviseWindow.mainPanel.remove(this.scoreLabel);
        reviseWindow.mainPanel.remove(this.score);
        reviseWindow.mainPanel.remove(this.saScroller);
        reviseWindow.mainPanel.remove(this.standard);

    }


    public class skipListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){

        }
    }

    public void setButton(JButton button){
        button.setSize(50,50);
        button.setFont(new Font("宋体",Font.BOLD,14));
        button.setBackground(Color.lightGray);
    }

    public class reviseListener implements FocusListener {
        @Override
        public void focusGained(FocusEvent e){
        }
        public void focusLost(FocusEvent e){
            currRank=Integer.parseInt(score.getText());
            System.out.println(currRank);
        }
    }

    public void loadAnswer(){
        this.answerContent.setText(reviseWindow.resultSet[1][index]);
        this.standardAnswer.setText(currentquestion.getAnswer());

    }
}
